import java.util.Arrays;

public class Clone implements Cloneable {

    int age;
    Dick dick =  new Dick();

    //指定的方法中抛出指定的异常 使用格式: throw new xxxException(“异常产生的原因”)
//    @Override
//    protected Object clone() throws CloneNotSupportedException{
//
//        return super.clone();
//        //这个super.clone()代表了什么？ 父类引用clone就是将父类的引用克隆成副本，返回值是Object
//    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Clone tmp = (Clone)super.clone();
        tmp.dick = (Dick)this.dick.clone();
        return tmp;
    }
    //构造方法
    public Clone(int age,int size) {
        this.age = age;
        this.dick.size = size;
    }
}

class Dick implements Cloneable{
    int size;

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Tesla {
    public static void main(String[] args) throws CloneNotSupportedException {
        Clone cl = new Clone(20,14);
        Clone ll = (Clone)cl.clone();
        ll.dick.size = 20;
        System.out.println(cl.dick.size);
        System.out.println(ll.dick.size);
    }

//    public static void main(String[] args) throws CloneNotSupportedException {
//        Clone cl = new Clone(20);
//        Clone ll = (Clone) cl.clone();
//        System.out.println(cl.age);
//        System.out.println(ll.age);
//        ll.age ++;
//        System.out.println(ll.age);
//        System.out.println(cl.age);
//    }
}
